var t = getApp();

Page({
    data: {
        title: "",
        parties: "",
        partiesclue: "",
        ht: [],
        htGet: {},
        checkeda: !1,
        checkedb: !1,
        id: "",
        url: "",
        sessin: "",
        src: "../../images/05.png",
        condition: !0
    },
    onLoad: function(a) {
        var e = t.globalData.htGet, i = [ {
            keyword: "签约主体",
            keyname: "parties",
            url: "SdraftDetail",
            text: e.parties
        }, {
            keyword: "合同前言",
            keyname: "preface",
            url: "SdraftDetail",
            text: e.preface
        }, {
            keyword: "交易概述",
            keyname: "summary",
            url: "SdraftDetail",
            text: e.summary
        }, {
            keyword: "甲方义务",
            keyname: "obliga",
            url: "SdraftOblig",
            text: e.obliga
        }, {
            keyword: "乙方义务",
            keyname: "obligb",
            url: "SdraftOblig",
            text: e.obligb
        }, {
            keyword: "丙方义务",
            keyname: "obligc",
            url: "SdraftOblig",
            text: e.obligc
        }, {
            keyword: "验收条款",
            keyname: "accept",
            url: "SdraftDetail",
            text: e.accept
        }, {
            keyword: "违约责任",
            keyname: "liabity",
            url: "SdraftDetail",
            text: e.liabity
        }, {
            keyword: "免责事由",
            keyname: "execept",
            url: "SdraftDetail",
            text: e.execept
        }, {
            keyword: "争议解决",
            keyname: "dispute",
            url: "SdraftDetail",
            text: e.dispute
        }, {
            keyword: "其他条款",
            keyname: "end",
            url: "SdraftOblig",
            text: e.end
        }, {
            keyword: "签署栏",
            keyname: "Signature",
            url: "SdraftDetail",
            text: e.Signature
        } ];
        (!e.obligc || e.obligc.length <= 0) && i.splice(5, 1), e.obligc && e.obligc.length > 0 && i.splice(5, 0), 
        this.setData({
            ht: i,
            htGet: e,
            id: a.id,
            url: a.url,
            sessin: a.sessin,
            Listurl: a.Listurl,
            TopName: a.TopName
        });
        var r = e.partAorB;
        "甲方" == r && this.setData({
            checkeda: !0
        }), "乙方" == r && this.setData({
            checkedb: !0
        });
    },
    onReady: function() {
        if (this.data.sessin !== wx.getStorageSync("PHPSESSID")) {
            var a = this;
            t.getWxLogin(function(t) {
                a.setData({
                    sessin: t
                });
            }), this.setData({
                checkeda: !1,
                checkedb: !1
            }), t.GetUrl();
        }
    },
    bindTitleinput: function(a) {
        t.globalData.htGet.title = a.detail.value, t.globalData.alternot = 1;
    },
    radioChange: function(a) {
        t.globalData.htGet.partAorB = a.detail.value, t.globalData.alternot = 1;
    },
    back: function() {
        var a = t.globalData.alternot, e = this.data.id, e = this.data.id, i = this.data.url, r = this.data.sessin, o = this;
        1 == a ? (t.globalData.alternot = "", wx.showModal({
            title: "提示",
            content: "你修改了合同内容，是否保存修改？",
            cancelText: "不保存",
            confirmText: "保存",
            success: function(a) {
                a.confirm ? o.SaveEdit() : (t.globalData.htGet = t.globalData.OrihtGet, wx.redirectTo({
                    url: "../MySht/MySht?id=" + t.globalData.OrihtGet.id + "&url=" + t.globalData.OrihtGet.url + "&sessin=" + t.globalData.OrihtGet.sessin + "&Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
                }));
            }
        })) : wx.redirectTo({
            url: "../MySht/MySht?id=" + e + "&url=" + i + "&sessin=" + r + "&Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
        });
    },
    SaveEdit: function(a) {
        var e = this, i = t.globalData.htGet, r = wx.getStorageSync("userInfo");
        i.obliga && i.obliga.length > 0 && (i.obliga = i.obliga.join("【&#下一条：^//////】")), 
        i.obligb && i.obligb.length > 0 && (i.obligb = i.obligb.join("【&#下一条：^//////】")), 
        i.obligc && i.obligc.length > 0 && (i.obligc = i.obligc.join("【&#下一条：^//////】")), 
        i.end && i.end.length > 0 && (i.end = i.end.join("【&#下一条：^//////】")), wx.request({
            url: t.url + "addon/Smcontract/Smcontract/editContract",
            data: {
                id: i.id,
                title: i.title,
                partAorB: i.partAorB,
                parties: i.parties,
                preface: i.preface,
                summary: i.summary,
                obliga: i.obliga,
                obligb: i.obligb,
                obligc: i.obligc,
                accept: i.accept,
                liabity: i.liabity,
                execept: i.execept,
                dispute: i.dispute,
                end: i.end,
                Signature: i.Signature,
                htbase: i.htbase,
                nickName: r.nickName,
                city: r.city,
                separator: "【&#下一条：^//////】"
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                var i = a.data;
                if (i > 1) wx.showToast({
                    title: "保存成功",
                    icon: "success",
                    duration: 2e3
                }), e.setData({
                    condition: !1,
                    addId: i
                }); else {
                    e.data.Listurl, e.data.TopName;
                    var r = e.data.url, o = e.data.url2, l = e.data.sessin;
                    wx.redirectTo({
                        url: "../MyCenter/MyCenter?url=" + r + "&url2=" + o + "&sessin=" + l + "&Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
                    }), wx.showToast({
                        title: "保存成功",
                        icon: "success",
                        duration: 2e3
                    });
                }
                t.globalData.PHPSESSID !== wx.getStorageSync("PHPSESSID") && (t.globalData.PHPSESSID = wx.getStorageSync("PHPSESSID"));
            },
            fail: function(t) {
                t && wx.showToast({
                    title: "保存失败无网络",
                    icon: "loading",
                    duration: 2600
                });
            }
        });
    },
    toExamMy: function(t) {
        wx.redirectTo({
            url: "../../pages/ExamMy/ExamMy?id=" + this.data.addId + "&htbase=SM"
        });
    },
    openContract: function(t) {
        this.data.Listurl, this.data.TopName, this.data.url, this.data.url2;
        var a = wx.getStorageSync("PHPSESSID");
        wx.redirectTo({
            url: "../../pages/MySht/MySht?id=" + this.data.addId + "&url=Smcontract/Smcontract/ContractDetail&url2=Smcontract/Smcontract/editContract&sessin=" + a + "&Listurl=Smcontract/Smcontract/&TopName=我起草的合同"
        });
    },
    toIndex: function(t) {
        wx.switchTab({
            url: "../Draft/Draft"
        });
    }
});